package bigdata.api.echart.datapush;

import common.utils.gsonutil.GsonUtil;
import datacenterbizapiexternal.datapush.domain.entity.GuizhouDsitribution;
import datacenterbizapiexternal.datapush.service.GuizhouDistributionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 描述:
 *
 * @author
 * @created 2017/6/21 19:33
 * @since v1.0.0
 */
@Controller
@RequestMapping("/distribution")
public class GuizhouDistributionController {
    @Autowired
    private GuizhouDistributionService guizhouDistributionService;
    @RequestMapping(params = { "method=guizhouNumber" })
    @ResponseBody()
    public void guizhouNumber(ModelMap model, String startTime,
                                 String endTime, String enumName, HttpServletResponse response) {

    }

    @RequestMapping(params = { "method=getFromExcel" })
    @ResponseBody()
    public String getFromExcel(ModelMap model, String startTime,
                              String endTime, String enumName, HttpServletResponse response) {
        String filePath = "G:\\corp\\corp_document\\大数据\\接口文档\\external-api\\个旅\\demo.xls";
        List<GuizhouDsitribution> list = guizhouDistributionService.getGuizhouDsitributionFromExcel(filePath);
        guizhouDistributionService.save(list);
        String res = GsonUtil.create().toJson(list);
        return res;
    }
    @RequestMapping(params = { "method=getGuizhou" })
    @ResponseBody()
    public String getGuizhou(String callback) {
        List<GuizhouDsitribution> list = guizhouDistributionService.getGuizhou();
        String res = GsonUtil.create().toJson(list);
        StringBuffer sb = new StringBuffer(callback).append("(").append(res).append(")");
        return sb.toString();
    }

}
